

var QControlPlaceholder = QWebControl.extend('QControlPlaceholder', {

	_savedPlaceholderPos : {},
	_timeout_func : null,
	
	load : function()
	{
		// this.resizeControlToPlace(); 
		var tmp_this = this;
		
		this._timeout_func = function(){tmp_this.resizeControlToPlace()};
		setTimeout(this._timeout_func, 1000);
		// setInterval(function(){tmp_this.resizeControlToPlace()}, 2000);
	},
	
	
	resizeControlToPlace : function (avoid_timeout)
	{
		if (!this.domElement)
			return;
		
		var jq_this = jQuery(this.domElement);
		var ctrl_to_place = this.getControlToPlace();
		
		// alert(this._savedPlaceholderPos);
		
		if (ctrl_to_place)
		{
			if (((this._savedPlaceholderPos.top != jq_this.offset().top) ||
				(this._savedPlaceholderPos.left != jq_this.offset().left) ||
				(this._savedPlaceholderPos.width != jq_this.width()) ||
				(this._savedPlaceholderPos.height != jq_this.height()))
				)
				
			{
				// alert("setBounds...");
				/*
				alert(jq_this.offset().top + "x" + jq_this.offset().left + "x" + 
					jq_this.width() + "x" + jq_this.height() + "\n" + 
					this._savedPlaceholderPos.top + "x" + this._savedPlaceholderPos.left + "x" +
					this._savedPlaceholderPos.width + "x" + this._savedPlaceholderPos.height);
					*/
				
				
				this._savedPlaceholderPos = {top: jq_this.offset().top, left: jq_this.offset().left, 
					width: jq_this.width(), height: jq_this.height()};

				ctrl_to_place.setBounds(jq_this.offset().top, jq_this.offset().left, 
					jq_this.width(), jq_this.height(), true);
				// ctrl_to_place.domElement.css("display", "block");
				jQuery(ctrl_to_place.domElement).css("display", "block");
				
				var tmp_this = this;
				this._timeout_func = function(){tmp_this.resizeControlToPlace()};
				
				if (avoid_timeout == true)
				{
					
				}
				else
					setTimeout(this._timeout_func, 2000);
			}
		}
	},
	
	destroyControl : function()
	{
		// alert("clearTimeout");
		clearTimeout(this._timeout_func);
	},
	
	getControlToPlace : function ()
	{
		var ctrl_to_place = this.getJsParam("controlToPlace");
		if (!ctrl_to_place)
			return null;
		// alert(ctrl_to_place);
		return GetQWebPage().getQWebControlById(ctrl_to_place);
	}

});